package Service;

import Utils.DbUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GetTableName {
    public List<String> GetTableName(HttpServletRequest req, HttpServletResponse resp) throws SQLException {
        Connection conn = DbUtil.getConnection(req);
        ResultSet rs = null;
        DatabaseMetaData metaData = conn.getMetaData();
        ResultSet tables = metaData.getTables((String) req.getSession().getAttribute("db"), null, "%", new String[]{"TABLE"});
        List<String> tableNames = new ArrayList<String>();
        while (tables.next()) {
            tableNames.add(tables.getString("TABLE_NAME"));
        }
        return tableNames;
    }
}
